layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate;

    //日期
    laydate.render({
        elem: '#signTime'
    });



    //自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 5){
                return '标题至少得5个字符啊';
            }
        }
        ,pass: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]
        ,content: function(value){
            layedit.sync(editIndex);
        }
    });

    //监听提交
    form.on('submit(demo2)', function(data){
        console.info(data.field);
        let url='/logisticsSign/insertAndUpdate';
        let date=data.field;
        $.ajax({
            type: 'post',
            url: url,
            data: date,
            dataType: 'json',
            success: function (response) {
                if (response.state ==1){
                    layer.msg('保存成功');
                    layerClose();
                    parent.table.reload('dataListTable');
                    //父页面提示信息
                    parent.layer.msg(response.msg);
                }else {
                    layerClose();
                    layer.msg('保存失败');
                }
            }
        })




        return false;
    });


    let id=getQueryString("id");//取到userLisst.html里面的id
    console.info(id);
    if (id) {//id!=null
        let data_={id:id};
        let url="/logisticsSign/selectOne";
        $.ajax({
            type: 'get',
            url: url,
            data: data_,
            dataType: 'json',
            success: function (response) {
                console.info(response);
                if (response!=1){
                    $("#signId").val(response.signId);
                    $("#orderId").val(response.orderId);
                    $("#signRecipients").val(response.signRecipients);
                    $("#signTime").val(response.signTime);
                    $("#signArea").val(response.signArea);
                    $("#signTel").val(response.signTel);
                }else {
                    layer.msg('保存失败');
                }
            }
        })
    }
    //表单赋值
    layui.$('#LAY-component-form-setval').on('click', function(){
        form.val('example', {
            "username": "贤心" // "name": "value"

        });
    });
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

});